<form class="layui-form seller-form"  action="" >

    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">商户订单号：</label>
            <div class="layui-input-inline" style="width:260px" >
                <input type="text" style="width:260px" name="order_sn_sh" lay-verify="title" placeholder="请输入订单关键字" autocomplete="off" class="layui-input">
            </div>
        </div> 

        <div class="layui-inline">
            <label class="layui-form-label">交易状态：</label>
            <div class="layui-input-inline">
                <select name="pay_status" id="pay_status">
                    <option value="">-- 全部 --</option>
                    <option value="SUCCESS">-- 支付成功 --</option>
                    <option value="REFUND">-- 退款 --</option>
                    <option value="REVOKED">-- 已撤销 --</option>
                </select>
            </div>
        </div>
  
        <div class="layui-inline">
            <label class="layui-form-label">支付时间：</label>
            <div class="layui-input-inline">
                <input type="text" id="time" name="time" placeholder="开始时间 到 结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="brand-search"><i class="iconfont icon-chaxun"></i>筛选</button>
        
            <button id="exportBtn" class="layui-btn layui-btn-sm layui-btn-disabled" lay-submit lay-filter="export-wxbill"><i
                class="iconfont icon-clouddownload" style="font-size: 20px !important;" disabled></i>导出</button> 
        </div>
    </div>

</form>

<div id="exportWxBill" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先筛选要导出的记录，默认导出全部
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<div class="table-body">
    <table id="brandTable" lay-filter="brandTable"></table>
</div>

<script>
    layui.use(['table','form','layer','laydate'],function(){
        var layer = layui.layer, table = layui.table,form = layui.form,date = layui.laydate;
        //执行渲染
        table.render({
            elem: '#brandTable', //指定原始表格元素选择器（推荐id选择器）
            height: 'full-115',
            cellMinWidth: '80',
            page: 'true',
            totalRow: true,
            limit:'20',
            id:'brandTable',
            url: "{:url('WxBill/indexfds')}",
            cols: [[ //标题栏
                {field: 'pay_time', title: '支付时间', width:160, align:'center'},  
                //{field: 'APP_ID', title: 'app_id', width:180, align:'center'},  
                //{field: 'MCH_ID', title: '商户id', width:120, align:'center'},  
                //{field: 'IMEI', title: '设备号', width:100, align:'center'},  
                {field: 'order_sn_wx', title: '微信订单号', width:260, align:'center'},  
                {field: 'order_sn_sh', title: '商户订单号', width:260, align:'center'},  
                {field: 'user_tag', title: '用户标识', width:300, align:'center'},  
                {field: 'pay_type', title: '交易类型', width:100, align:'center'},  
                {field: 'pay_status', title: '交易状态', width:100, align:'center'},  
                {field: 'bank', title: '付款银行', width:100, align:'center'},  
                {field: 'money_type', title: '货币种类', width:100, align:'center'},  
                {field: 'total_amount', title: '总金额', width:100, align:'center', totalRow: true},  
                //{field: 'coupon_amount', title: '代金券或立减优惠金额', width:100, align:'center'},  
                {field: 'refund_number_wx', title: '微信退款单号', width:260, align:'center'},  
                {field: 'refund_number_sh', title: '商户退款单号', width:320, align:'center'},  
                {field: 'refund_amount', title: '退款金额', width:100, align:'center', totalRow: true},  
                //{field: 'coupon_refund_amount', title: '代金券或立减优惠退款金额', width:100, align:'center'},  
                {field: 'refund_type', title: '退款类型', width:100, align:'center'},  
                {field: 'refund_status', title: '退款状态', width:100, align:'center'},  
                {field: 'goods_name', title: '商品名称', width:160, align:'center'},  
                //{field: 'service_charge', title: '手续费', width:100, align:'center'},  
                //{field: 'rate', title: '费率', width:100, align:'center'},  
            ]], //设置表头
            done: function(res, curr, count){
                // 判断加载结果数量是否大于0
                if(count>0){
                    $("#exportBtn").removeClass("layui-btn-disabled");
                    $('#exportBtn').removeAttr("disabled");
                } else {
                    $('#exportBtn').addClass("layui-btn-disabled");
                    $('#exportBtn').attr("disabled", true);
                }
            }
        });

        date.render({
            elem: '#time',
            range: '到'
        });

        form.on('submit(brand-search)', function(data){
            layui.table.reload('brandTable', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
 
        //微信账单导出
        layui.form.on('submit(export-wxbill)', function (data) {
            layer.open({
                type: 1,
                title: '微信账单导出',
                area: ['400px', '248px'], //宽高
                btn: ['确定', '取消'],
                content: $("#exportWxBill").html(),
                success: function () {
                    $(':focus').blur();
                    this.enterEsc = function(event){
                        if(event.keyCode === 13){
                            if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                                $(".layui-layer-btn0").addClass("layui-btn-disabled");

                                //判断是否有选中
                                var filter = $(".seller-form").serialize(); 
                                $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                                var data = $(".export-form:last").serializeArray();
                                
                                if($.trim(data[0]['value']) == '') {
                                    layer.msg('请填写任务名称！', { time: 1300 });
                                    $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    return false;
                                }

                                data.push({ 'name': 'model', 'value': 'WxBillFds' });
                                JsPost("{:url('Ietask/export')}", data, function (res) {
                                        layer.msg(res.msg, { time: 1500 }, function () {
                                            if (res.status) {
                                                layer.closeAll();
                                                //执行跳转
                                                var topLayui = parent === self ? layui : top.layui;
                                                topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                            } else {
                                                $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                            }
                                        });
                                    }
                                );
                            }
                            return false; //阻止系统默认回车事件
                        }
                    };
                    $(document).on('keydown', this.enterEsc);	//监听键盘事件，关闭层
                },
                yes: function () {
                    if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                        $(".layui-layer-btn0").addClass("layui-btn-disabled");

                        //判断是否有选中
                        var filter = $(".seller-form").serialize(); 
                        $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                        var data = $(".export-form:last").serializeArray();
                        
                        if($.trim(data[0]['value']) == '') {
                            layer.msg('请填写任务名称！', { time: 1300 });
                            $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                            return false;
                        }

                        data.push({ 'name': 'model', 'value': 'WxBillFds' });
                        JsPost("{:url('Ietask/export')}", data, function (res) {
                                layer.msg(res.msg, { time: 1500 }, function () {
                                    if (res.status) {
                                        layer.closeAll();
                                        //执行跳转
                                        var topLayui = parent === self ? layui : top.layui;
                                        topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                    } else {
                                        $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    }
                                });
                            }
                        );
                    }
                }, btn2: function () {
                    layer.closeAll();
                }, end: function(){
                    $(document).off('keydown', this.enterEsc);	        //解除键盘关闭事件
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>